package com.molichuxing.services.infrastructure.service.impl;

import com.molichuxing.services.infrastructure.bean.StatisticsOrderBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.StatisticsOrderMapper;
import com.molichuxing.services.infrastructure.dto.request.create.StatisticsOrderCreateDto;
import com.molichuxing.services.infrastructure.dto.response.PieChartDto;
import com.molichuxing.services.infrastructure.service.BasicdataStatisticsOrderService;
import com.molichuxing.services.property.StatisticsOrderTypeEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

/**
 * @Author: renzhengyu
 * @Description:
 * @Date: Created in 10:11 2020/1/6
 * @Modified By:
 **/
@Service("basicdataStatisticsOrderService")
public class BasicdataStatisticsOrderServiceImpl implements BasicdataStatisticsOrderService {

    @Resource
    private StatisticsOrderMapper statisticsOrderMapper;


    @Override
    public int createStatisticsOrder(StatisticsOrderCreateDto statisticsOrderCreateDto) {
        StatisticsOrderBean statisticsOrderBean = Convert.toStatisticsOrderBean(statisticsOrderCreateDto);
        return statisticsOrderMapper.create(statisticsOrderBean);
    }

    /**
     * 根据时间和类型查询折线图信息
     * @param statisticsOrderTypeEnum
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public List<PieChartDto> getStatisticsOrderByDate(StatisticsOrderTypeEnum statisticsOrderTypeEnum, LocalDate startTime, LocalDate endTime) {
        return statisticsOrderMapper.getStatisticsOrderByDate(statisticsOrderTypeEnum.getValue(),startTime,endTime);
    }

    /**
     * 根据时间和类型查询时间区间内的订单总数
     * @param statisticsOrderTypeEnum
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public Integer getStatisticsOrderCountByDate(StatisticsOrderTypeEnum statisticsOrderTypeEnum, LocalDate startTime, LocalDate endTime) {
        return statisticsOrderMapper.getStatisticsOrderCountByDate(statisticsOrderTypeEnum.getValue(),startTime,endTime);
    }
}
